View Javadoc
1 package com.fc.taglibs.castor; 2 3 import java.io.*; 4 import java.util.ArrayList; 5 import javax.naming.*; 6 import javax.servlet.jsp.*; 7 import javax.servlet.jsp.tagext.*; 8 9 import org.exolab.castor.jdo.DataObjects; 10 import org.exolab.castor.jdo.Database; 11 import org.exolab.castor.jdo.ClassNotPersistenceCapableException; 12 import org.exolab.castor.jdo.TransactionNotInProgressException; 13 import org.exolab.castor.jdo.PersistenceException; 14 15 public class CastorUpdateTag extends BodyTagSupport 16 { 17 18 /*** 19 * The name of this tag 20 */ 21 private static String _tagName = "CastorUpdateTag"; 22 23 /*** 24 * The object to update 25 */ 26 private Object data; 27 28 /*** 29 * The database to perform the update 30 */ 31 private Database db = null; 32 33 /*** 34 * The JDO object 35 */ 36 private DataObjects jdo = null; 37 38 /*** 39 * The name of the JDO object 40 * to be retrieved from page scope 41 */ 42 private String jdoName = null; 43 44 /*** 45 * The name of the data object 46 * to be retrieved from page scope 47 */ 48 private String name = null; 49 50 /*** 51 * Whether we are starting 52 * a new transaction 53 */ 54 private boolean newTransaction = false; 55 56 /*** 57 * Sets the jdo name 58 */ 59 public void setJdoName(String _jdoName) 60 { 61 this.jdoName = _jdoName; 62 } 63 64 /*** 65 * Sets the name of the page scoped attribute 66 * that is the bean we are deleting/updating 67 */ 68 public void setName(String _name) 69 { 70 this.name = _name; 71 } 72 73 /*** 74 * Do the start tag bit 75 */ 76 public int doStartTag() throws JspException 77 { 78 79 try 80 { 81 /* 82 * Get the data object 83 */ 84 if (pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE)!=null) 85 data = pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE); 86 else if (pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE)!=null) 87 data = pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE); 88 else if (pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE)!=null) 89 data = pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE); 90 else if (pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE)!=null) 91 data = pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE); 92 else 93 { 94 String msg = "Data object " + this.name + " could not be found in any scope."; 95 log(msg,null); 96 throw new Exception(msg); 97 } 98 99 /* 100 * Check to see if this tag is nested within a transactional tag 101 * Get the database from the parent tag and then create the data 102 */ 103 CastorTransactionInitiator t = (CastorTransactionInitiator)findAncestorWithClass(this, CastorTransactionInitiator.class); 104 if (t!=null) 105 { 106 db = t.getDatabase(); 107 log ("Got transaction from parent tag", null); 108 db.update(data); 109 } 110 else 111 { 112 String msg = "Tag not nested within a CastorTransactionTag."; 113 log(msg,null); 114 throw new Exception(msg); 115 //code below is legacy from standalone tag 116 //may reimplement this later. 117 //for now only use within transaction tag. 118 //jdo = (DataObjects)pageContext.getAttribute(this.jdoName,PageContext.PAGE_SCOPE); 119 //db = jdo.getDatabase(); 120 //newTransaction = true; 121 //db.begin(); 122 } 123 124 125 } 126 catch(ClassNotPersistenceCapableException e) 127 { 128 log(e.getMessage() , e); 129 throw new JspTagException(e.getMessage()); 130 } 131 catch(TransactionNotInProgressException e) 132 { 133 log(e.getMessage() , e); 134 throw new JspTagException(e.getMessage()); 135 } 136 catch(PersistenceException e) 137 { 138 log(e.getMessage() , e); 139 throw new JspTagException(e.getMessage()); 140 } 141 catch(Exception e) 142 { 143 log(e.getMessage() , e); 144 throw new JspTagException(e.getMessage()); 145 } 146 return EVAL_PAGE; 147 } 148 149 private void log(String msg,Exception e) 150 { 151 if (e!=null) 152 { 153 System.err.println(_tagName + ": " + msg); 154 e.printStackTrace(); 155 } 156 else 157 { 158 System.out.println(_tagName + ": " + msg); 159 } 160 } 161 }

This page was automatically generated by Maven